// owner-app/pages/select-house/index.js
import {handlerGobackClick} from "../../../utils/util";
import {Pets} from "../../../models/pets";


const pets = new Pets()
Page({

  /**
   * 页面的初始数据
   */
  data: {
    prevPage:null,
    houseList: [],
    defaultValue:""
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    if(options.id){
      this.setData({
        defaultValue:options.id
      })
    }
  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {
    this.initPageData()
  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {
    let curPages = getCurrentPages()  //获取当前页面js里的所有信息
    let prevPage = curPages[curPages.length - 2]
    this.setData({
      prevPage
    })
  },
  handlerGobackClick,
  selectedRadio(e){
    let {id,title} = e.detail

    //设置前一页的值和名字
    this.data.prevPage.setData({
      size:id,
      sizeName:title
    })
    wx.navigateBack()
  },
  goApply(){
  },
  initPageData(){
    pets.getPetSize()
        .then((res)=>{
          let arr = []
          arr = res.result.map((item,index)=>{
            return {title:item.text,value:item.value}
          })
          this.setData({
            houseList:arr
          })

        })
        .catch((err)=>{
          console.log(err);})
  }
})
